import { axios } from "@/services/axios";
import {useEffect, useMemo, useState} from "react";

const Customer = {
  get: (code) => axios.get(`api/customer/${code}`),
  query: (bytstatus) => axios.get(`api/customertemp/list/${bytstatus}`),
  getcustomer: data => axios.get(`api/customertemp/${data.id}`),
  getcustomerlist: params => axios.post(`api/customertemp/list`, params),
  createcustomer: data => axios.post("api/customertemp", data),
  getcustomerid: data => axios.get("api/customertemp", data),
  savecustomer: data => axios.post(`api/customertemp/${data.id}`, data),
  deletecustomer: data => axios.post(`api/customertemp/delete/${data.id}`),
  getemployee: (code) => axios.get(`api/employeetemp/${code}`),
  queryemployee: data => axios.post(`api/employeetemp/list`, data),
  querydepartment: data => axios.post(`api/department/list`, data),
  queryyusuan: data => axios.post(`api/yusuancode/list`, data),
  querypurchaseemployee: data => axios.post(`api/purchaseemployeetemp/list`, data),
  queryshenjiemployee: data => axios.post(`api/shenjiemployeetemp/list`, data),
  
};
export function useOrgunit(orgunitcode) {
  const [optionsLoaded, setOptionsLoaded] = useState(false);
  const [options, setOptions] = useState([]);

  useEffect(() => {
    let cancelDataSourceLoading = false;
    let params={
      code: "",
      name: "",
      userid: 0,
    }
    Customer.querydepartment(params).then(data => {
      if (!cancelDataSourceLoading) {
        setOptionsLoaded(true);
        setOptions(data);
    }});

    return () => {
      cancelDataSourceLoading = true;
    };
  }, [orgunitcode]);

  return useMemo(() => ({ optionsLoaded, options }), [optionsLoaded, options]);
}
// export function UseQueryCusomer(bytstatus) {
//   const [customerloaded, setcustomerloaded] = useState(false);
//   const [customer, setcustomer] = useState([]);

//   useEffect(() => {
//     let cancelDataSourceLoading = false;
//     Customer.query(bytstatus).then(data => {
//       if (!cancelDataSourceLoading) {
//         setcustomerloaded(true);
//         setcustomer(data);
//     }});

//     return () => {
//       cancelDataSourceLoading = true;
//     };
//   }, [bytstatus]);

//   return useMemo(() => ({ customerloaded, customer }), [customerloaded, customer]);
// }
export default Customer;


